/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * <p>Project: javase202202 - D2
 * <p>Powered by Lisi On 2022-05-30 14:48:35
 * <p>Created by IntelliJ IDEA
 *

 * @version 1.0
 * @since 17
 */
public class D2 {
    public static void main(String[] args) throws ParseException {
        //TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
        //日期工具类
        Date d = new Date();
        System.out.printf("%tF %<tT%n",d);
        System.out.printf("%tF %<tT%n",0L);

        //d.getTime()
        System.out.println(d);
        System.out.println(d.toString());
        d.setTime(0);
        System.out.printf("%tF %<tT%n",d);


        //案例：计算两个日期之间有多少天？
        //1985年10月22日 1万天30年 3万天


        //日历工具类
        Calendar c = Calendar.getInstance();
        c.set(2022, Calendar.FEBRUARY,24);
        Date start = c.getTime();
        System.out.printf("%tF %<tT%n",start);
        d = new Date();
        System.out.printf("%tF %<tT%n",d);

        long days = (d.getTime() - start.getTime())/(1000*60*60*24);
        System.out.println(days);

        //现在日期
        Date nn = new Date();
        //案例计算 10天的日期
        Date aa = new Date(nn.getTime() - (1000*60*60*24*10));
        System.out.printf("%tF %<tT%n",aa);

        Calendar c2 = Calendar.getInstance();
        c2.set(Calendar.DAY_OF_MONTH,1);

        Date d3 = c2.getTime();
        System.out.printf("%tF %<tT%n",d3);

        Calendar c3 = Calendar.getInstance();
        int year = c3.get(Calendar.YEAR);
        int month = c3.get(Calendar.MONTH)+1;
        System.out.println(year);
        System.out.println(month);

        //c3.getTime() 返回Date对象
        //c3.set();
        //c3.set();

        //Date 对象 转换为 Calendar对象
        Calendar c4 = Calendar.getInstance();
        c4.setTime(new Date());
        System.out.printf("%tF %<tT%n",c4);

        //Calendar 对象 转换为 Date对象
        Date d4 = c4.getTime();
        System.out.printf("%tF %<tT%n",d4);

        //创建一个指定的日期  Date (2022 5 31 23 59 59)
        Calendar c5 = Calendar.getInstance();
        c5.set(Calendar.YEAR,2022);
        c5.set(Calendar.MONTH,5-1);
        c5.set(Calendar.DAY_OF_MONTH,31);
        c5.set(Calendar.HOUR_OF_DAY,23);
        c5.set(Calendar.MINUTE,59);
        c5.set(Calendar.SECOND,59);
        System.out.printf("%tF %<tT%n",c5);

        //格式date的工具类, 格式日期对象，结果是字符串，将指定格式的字符串，解析转换为Date
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        System.out.println(sdf.format(c5.getTime()));

        Date d6 = sdf.parse("1985年12月22日 8:50:30");
        System.out.printf("%tF %<tT %n",d6);

        SimpleDateFormat s2 = new SimpleDateFormat("MM月dd日 E");
        System.out.println(s2.format(d6));

        //2000-8-8 这一天是星期几
        Calendar c9 = Calendar.getInstance();

        c9.set(2000,Calendar.AUGUST,8);

        //c9.set(Calendar.YEAR,2000);
        //c9.set(Calendar.MONTH,8-1);
        //c9.set(Calendar.DAY_OF_MONTH,8);
        System.out.println(sdf.format(c9.getTime()));

        SimpleDateFormat s3 = new SimpleDateFormat("E z Z"); //cst
        System.out.printf("%s",s3.format(c9.getTime()));


    }
}
